package com.tuliyou.common.util;

import com.tuliyou.common.constant.ResponseStatusCodeConstant;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 统一响应结果封装类
 * @param <T> 数据类型
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {
    /** 响应码 */
    private Integer code;

    /** 响应消息 */
    private String message;

    /** 响应数据 */
    private T data;

    // 成功响应的方法
    public static <T> Result<T> success() {
        return new Result<>(ResponseStatusCodeConstant.SUCCESS, "success", null);
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(ResponseStatusCodeConstant.SUCCESS, "success", data);
    }

    public static <T> Result<T> success(String message, T data) {
        return new Result<>(ResponseStatusCodeConstant.SUCCESS, message, data);
    }

    // 失败响应的方法
    public static <T> Result<T> error() {
        return new Result<>(ResponseStatusCodeConstant.ERROR, "error", null);
    }

    public static <T> Result<T> error(String message) {
        return new Result<>(ResponseStatusCodeConstant.ERROR, message, null);
    }

    public static <T> Result<T> error(int code, String message) {
        return new Result<>(code, message, null);
    }

    public static <T> Result<T> error(String message, T data) {
        return new Result<T>(ResponseStatusCodeConstant.ERROR, message, data);
    }

    // 特定错误类型的方法
    public static <T> Result<T> paramError() {
        return new Result<>(ResponseStatusCodeConstant.PARAM_ERROR, "参数错误", null);
    }

    public static <T> Result<T> paramError(String message) {
        return new Result<>(ResponseStatusCodeConstant.PARAM_ERROR, message, null);
    }

    public static <T> Result<T> notFound() {
        return new Result<>(ResponseStatusCodeConstant.DATA_NOT_FOUND, "数据不存在", null);
    }

    public static <T> Result<T> notFound(String message) {
        return new Result<>(ResponseStatusCodeConstant.DATA_NOT_FOUND, message, null);
    }

    public static <T> Result<T> userNotLogin() {
        return new Result<>(ResponseStatusCodeConstant.USER_NOT_LOGIN, "用户未登录", null);
    }

    public static <T> Result<T> permissionDenied() {
        return new Result<>(ResponseStatusCodeConstant.PERMISSION_DENIED, "权限不足", null);
    }

}
